package com.mimosa.common.system.user;

import java.util.Collections;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.mimosa.common.entity.BaseEntity;
import com.mimosa.common.system.role.TRole;

@Entity
@Table(name = "T_Group")
public class TGroup extends BaseEntity {
	/**
	 * 用户组名称 （32）
	 */
	@Column(length = 32, nullable = false)
	private String groupName;

	/**
	 * 用户组编码（32）
	 */
	@Column(length = 32, nullable = true)
	private String groupCode;

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public String getGroupCode() {
		return groupCode;
	}

	public void setGroupCode(String groupCode) {
		this.groupCode = groupCode;
	}

	public String getGroupDesc() {
		return groupDesc;
	}

	public void setGroupDesc(String groupDesc) {
		this.groupDesc = groupDesc;
	}

	public String getGroupType() {
		return groupType;
	}

	public void setGroupType(String groupType) {
		this.groupType = groupType;
	}

	/**
	 * 用户组描述（512）
	 */
	@Column(length = 512, nullable = true)
	private String groupDesc;
	/**
	 * 用户组类型
	 */
	@Column(length = 8, nullable = false)
	private String groupType = GroupType.CUSTOM.name();

	@SuppressWarnings("unchecked")
	@ManyToMany(cascade = { javax.persistence.CascadeType.ALL })
	@JoinTable(name = "T_USER_GROUP", joinColumns = { @JoinColumn(name = "group_id") }, inverseJoinColumns = {
			@JoinColumn(name = "user_id") })
	private Set<TUser> userList = Collections.EMPTY_SET;

	@SuppressWarnings("unchecked")
	@ManyToMany(cascade = { javax.persistence.CascadeType.ALL })
	@JoinTable(name = "T_ROLE_GROUP", joinColumns = { @JoinColumn(name = "group_id") }, inverseJoinColumns = {
			@JoinColumn(name = "role_id") })
	private Set<TRole> roleList = Collections.EMPTY_SET;

	public Set<TUser> getUserList() {
		return userList;
	}

	public void setUserList(Set<TUser> userList) {
		this.userList = userList;
	}

	public Set<TRole> getRoleList() {
		return roleList;
	}

	public void setRoleList(Set<TRole> roleList) {
		this.roleList = roleList;
	}
}
